import React, {FC, useEffect, useState} from 'react';
import styles from './DownloadDemo.less'
import {Button, Card, Space} from "antd";
import {ajaxUtilInstance} from "@/utils/SystemAjaxUtil";
import {AjaxUtil} from "@/utils/AjaxUtil";

interface DownloadDemoProps {
}

const PDF_URL = 'https://arxiv.org/pdf/quant-ph/0410100.pdf';
const DownloadDemo: FC<DownloadDemoProps> = (props) => {
    const {children} = props;

    useEffect(() => {
        console.log('DownloadDemo 组件挂载完毕!');
    }, []);

    console.log('DownloadDemo 组件render!');
    const [downloading, setDownloading] = useState<boolean>(false);
    const onDownload01 = async () => {
        setDownloading(true);
        await AjaxUtil.fileDownload({url: PDF_URL}, function (headers) {
            return '测试.pdf';
        })
        setDownloading(false);
    }
    return (
        <div>
            <Space direction="vertical" style={{width: '100%'}}>
                <Card>
                    <h2>下载</h2>
                </Card>
                <Card>
                    <Space>
                        <Button onClick={onDownload01} disabled={downloading}>点击下载</Button>
                    </Space>
                </Card>
            </Space>
        </div>
    );
};

export default DownloadDemo;
